package com.gzq.common_core;

import android.app.Application;
import android.content.Context;

import com.google.auto.service.AutoService;
import com.google.gson.GsonBuilder;
import com.gzq.common_core.base.AppLifecycle;
import com.gzq.common_core.base.GlobalModel;
import com.gzq.common_core.base.config.CrashManagerConfig;
import com.gzq.common_core.base.config.GlobalConfig;
import com.gzq.common_core.base.config.GsonConfig;
import com.gzq.common_core.base.config.OkhttpConfig;
import com.gzq.common_core.base.config.RetrofitConfig;
import com.gzq.common_core.base.config.SessionManagerConfig;
import com.gzq.common_core.base.config.ToastConfig;
import com.gzq.common_core.crash.CaocConfig;
import com.gzq.common_core.session.SessionManager;
import com.gzq.common_core.toast.T;
import com.gzq.common_core.toast.style.ToastAlipayStyle;
import com.gzq.common_core.toast.style.ToastBlackStyle;
import com.xiaojinzi.component.Component;
import com.xiaojinzi.component.impl.application.ModuleManager;
import com.xiaojinzi.component.support.RxErrorIgnoreUtil;

import me.jessyan.autosize.unit.Subunits;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import timber.log.Timber;

@AutoService({GlobalConfig.class, AppLifecycle.class})
public class Global implements GlobalConfig ,AppLifecycle{
    @Override
    public void applyOptions(Application application, GlobalModel.Builder builder) {
        builder
                .baseurl("http://www.baidu.com/")
                .autoSize(false, false, Subunits.PT)
                .gsonConfiguration((application12, gsonBuilder) -> {

                })
                .okhttpConfiguration((application13, okhttpBuilder) -> {

                })
                .retrofitConfiguration((application14, retrofitBuilder) -> {

                })
                .sessionManagerConfiguration((application15, sessionManager) -> {
                    //将这个对象回调出来的目的是，增强扩展性，后期如果不满意默认的MMKV作为本地缓存框架，
                    // 可以轻松换成其他方式缓存
                })
                .crashManagerConfiguration((application16, crashBuilder)
                        -> crashBuilder.enabled(true))
                .toastStyle((application1, toast)
                        -> toast.initStyle(new ToastBlackStyle()));
    }

    @Override
    public void attachBaseContext(Application app, Context context) {

    }

    @Override
    public void onCreate(Application app) {
        Timber.e("初始化的执行情况");
        // 初始化
        Component.init(app, BuildConfig.DEBUG);
        // 如果你依赖了 rx 版本,需要配置这句代码,否则删除这句
        RxErrorIgnoreUtil.ignoreError();
        // 注册其他业务模块,注册的字符串是上面各个业务模块配置在 build.gradle 中的 HOST
        ModuleManager.getInstance().registerArr("app","test1");
        if (BuildConfig.DEBUG) {
            // 框架还带有检查重复的路由和重复的拦截器等功能,在 `debug` 的时候开启它
            ModuleManager.getInstance().check();
        }
    }

    @Override
    public void onTerminate(Application app) {

    }

    @Override
    public int priority() {
        return 0;
    }
}
